<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>下达任务</title>
    <link rel="stylesheet" href="layui/css/layui.css">
    <link rel="stylesheet" href="css/assignMission.css">
</head>
<body>
<div class="task layui-bg-green">下达完工报产任务</div>
<form class="layui-form">
    <input type="hidden" name="requestTime">
    <input type="hidden" name="requestUUID">
    <input type="hidden" name="taskType" value="PRODUCT_OK">
    <div class="layui-form-item layui-row">
        <div class="layui-col-md4">
            <label class="layui-form-label">任务编号</label>
            <div class="layui-input-inline">
                <input type="text" name="taskId" required lay-verify="required" placeholder="请输入任务编号" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-col-md4">
            <label class="layui-form-label">物料类型</label>
            <div class="layui-input-inline">
                <select name="materialType">
                    <option value="">请选择物料</option>
                    <option value="前轴">前轴</option>
                    <option value="扭梁">扭梁</option>
                    <option value="副车架">副车架</option>
                </select>
            </div>
        </div>
        <div class="layui-col-md4">
            <label class="layui-form-label">物料数量</label>
            <div class="layui-input-inline">
                <input type="text" name="count" required lay-verify="required" placeholder="请输入物料编号列表"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item layui-row">
        <div class="layui-col-md4">
            <label class="layui-form-label">图号</label>
            <div class="layui-input-inline">
                <input type="text" name="material" required lay-verify="required" placeholder="请输入物料编号"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-col-md4">
            <label class="layui-form-label">料框编号</label>
            <div class="layui-input-inline">
                <input type="text" name="containerId" required lay-verify="required" placeholder="请输入料框编号"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-col-md4">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="completion">立即下达</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </div>
</form>
<hr class="layui-bg-green">

<div class="task layui-bg-green">下达出库任务</div>
<form class="layui-form">
    <input type="hidden" name="requestTime">
    <input type="hidden" name="requestUUID">
    <input type="hidden" name="taskType" value="OUT_GOING">
    <div class="layui-form-item layui-row">
        <div class="layui-col-md4">
            <label class="layui-form-label">任务编号</label>
            <div class="layui-input-inline">
                <input type="text" name="taskId" required lay-verify="required" placeholder="请输入任务编号" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-col-md4">
            <label class="layui-form-label">图号</label>
            <div class="layui-input-inline">
                <input type="text" name="material" required lay-verify="required" placeholder="请输入物料编号"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item layui-row">
        <div class="layui-col-md4">
            <label class="layui-form-label">物料类型</label>
            <div class="layui-input-inline">
                <select name="materialType">
                    <option value="">请选择物料</option>
                    <option value="前轴">前轴</option>
                    <option value="扭梁">扭梁</option>
                    <option value="副车架">副车架</option>
                </select>
            </div>
        </div>
        <div class="layui-col-md4">
            <label class="layui-form-label">物料数量</label>
            <div class="layui-input-inline">
                <input type="text" name="count" required lay-verify="required" placeholder="请输入物料编号列表"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-col-md4">
            <div class="layui-input-block">
                <!--空-->
            </div>
        </div>
        <div class="layui-col-md4">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="completion">立即下达</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </div>
</form>
<hr class="layui-bg-green">

<div class="task layui-bg-green">下达返工出库任务</div>
<form class="layui-form">
    <input type="hidden" name="requestTime">
    <input type="hidden" name="requestUUID">
    <input type="hidden" name="taskType" value="REPAIR">
    <div class="layui-form-item layui-row">
        <div class="layui-col-md4">
            <label class="layui-form-label">任务编号</label>
            <div class="layui-input-inline">
                <input type="text" name="taskId" required lay-verify="required" placeholder="请输入任务编号" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item layui-row">
        <div class="layui-col-md4">
            <label class="layui-form-label">料框编号</label>
            <div class="layui-input-inline">
                <input type="text" name="containerId" required lay-verify="required" placeholder="请输入料框编号"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-col-md4">
            <div class="layui-input-block">
                <!--空-->
            </div>
        </div>

        <div class="layui-col-md4">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="completion">立即下达</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </div>

</form>
<hr class="layui-bg-green">

<div class="task layui-bg-green">下达退料任务</div>
<form class="layui-form">
    <input type="hidden" name="requestTime">
    <input type="hidden" name="requestUUID">
    <input type="hidden" name="taskType" value="RETREAT">
    <div class="layui-form-item layui-row">
        <div class="layui-col-md4">
            <label class="layui-form-label">任务编号</label>
            <div class="layui-input-inline">
                <input type="text" name="taskId" required lay-verify="required" placeholder="请输入任务编号" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-col-md4">
            <label class="layui-form-label">物料类型</label>
            <div class="layui-input-inline">
                <select name="materialType">
                    <option value="">请选择物料</option>
                    <option value="前轴">前轴</option>
                    <option value="扭梁">扭梁</option>
                    <option value="副车架">副车架</option>
                </select>
            </div>
        </div>
        <div class="layui-col-md4">
            <label class="layui-form-label">物料数量</label>
            <div class="layui-input-inline">
                <input type="text" name="count" required lay-verify="required" placeholder="请输入物料编号列表"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item layui-row">
        <div class="layui-col-md4">
            <label class="layui-form-label">图号</label>
            <div class="layui-input-inline">
                <input type="text" name="material" required lay-verify="required" placeholder="请输入物料编号"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-col-md4">
            <label class="layui-form-label">料框编号</label>
            <div class="layui-input-inline">
                <input type="text" name="containerId" required lay-verify="required" placeholder="请输入料框编号"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-col-md4">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="completion">立即下达</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </div>
</form>
<hr class="layui-bg-green">

</body>
</html>
<script src="js/jquery.js"></script>
<script src="layui/layui.all.js"></script>
<script>
    var hostIp = window.location.hostname;
    var hostPort = window.location.port;
    var url = "http://" + hostIp + ":" + hostPort + "/rfid/issueTask";
    $(function () {
        var form = layui.form;
        form.on('submit(completion)', function (data) {
            // console.log(data);
            data.field.requestTime = new Date().getTime();
            data.field.requestUUID = uuid();
            /*var choose = data.form.getElementsByClassName("choose");
            if (choose != null) {
                var vals = [];
                $(choose).each(function () {
                    if ($(this).is(":checked")) {
                        vals.push($(this).val());
                    }
                });
            }
            data.field.materials = vals;*/
            /*var materials = data.form.getElementsByClassName("materialId");
            console.log(materials);
            if (materials != null) {
                var vals = [];
                $(materials).each(function () {
                    if ($(this).val() != null && $(this).val() != "")
                        vals.push($(this).val());
                });
            }
            data.field.materials = vals;*/


            console.log(data.field);
            $.ajax({
                url: url,
                type: 'POST',
                contentType: 'text/json; charset=UTF-8',
                async: false,
                dataType: 'json',
                data: JSON.stringify(data.field),
                success: function (response) {
                    layer.confirm(response.message);
                    // console.log(response);
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
    });


    /*function addMaterial(value) {
        var line = "<div class='layui-input-inline'><input type='text' placeholder='请输入物料编号'autocomplete='off' class='layui-input materialId'></div>";
        var divs = $(value).parent().find("div");
        $(value).parent().append(line);
    }*/


    function uuid() {
        var s = [];
        var hexDigits = "0123456789abcdef";
        for (var i = 0; i < 36; i++) {
            s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
        }
        s[14] = "4";
        s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);
        s[8] = s[13] = s[18] = s[23] = "";

        var uuid = s.join("");
        return uuid;
    }

    // author:kingdomjc
</script>
